// Package requests 处理请求数据和表单验证
package requests

import (
	"github.com/gofiber/fiber/v2"
	"github.com/thedevsaddam/govalidator"
)

type UserRequest struct {
	Avatar string `json:"avatar" valid:"avatar"`
	Name   string `json:"name" valid:"name"`
	Email  string `json:"email" valid:"email"`
	Phone  string `json:"phone" valid:"phone"`
	Gender uint8  `json:"gender" valid:"gender"`
}

func ValidateUser(c *fiber.Ctx, request *UserRequest) map[string][]string {
	c.QueryParser(request)
	c.BodyParser(request)
	rules := govalidator.MapData{
		"name":   []string{"min_cn:2", "max_cn:8"},
		"email":  []string{"email"},
		"phone":  []string{"phone"},
		"gender": []string{"in:1,2"},
	}

	messages := govalidator.MapData{
		// "name": []string{
		//     "required:名称为必填项",
		//     "min_cn:名称长度需至少 2 个字",
		//     "max_cn:名称长度不能超过 8 个字",
		// },
		// "description": []string{
		//     "min_cn:描述长度需至少 3 个字",
		//     "max_cn:描述长度不能超过 255 个字",
		// },
	}

	return Validate(request, rules, messages)
}
